Ext.define('Emp.view.Header', {
	extend: 'Ext.panel.Panel',
	alias: 'widget.xheader',
	
	requires: ['Emp.model.Dictionary'],
	
	initComponent: function() {
        Ext.apply(this, {
			border: false,
			baseCls: 'x-plain',
			html: '<img src="' + PATH + '/resources/images/login-logo.png" />',
			height: 45,
			dockedItems: [{
				xtype: 'toolbar',
				baseCls: 'x-plain',
				border: false,
				dock: 'bottom',
				items: ['->', '欢迎你：' + USER_NAME + '&nbsp;&nbsp;&nbsp;&nbsp;', {
					text: '更改密码',
					iconCls: 'login',
					action: 'changePassword',
					handler: function() {
						Ext.create('Emp.view.PasswordEdit').show();
					}
				}, {
					text: '注&nbsp;&nbsp;销',
					iconCls: 'logout',
					handler: function() {
						Ext.Msg.show({
							title: '提示',
							msg: '确认注销?',
							buttons: Ext.Msg.YESNOCANCEL,
							fn: function(buttonId, text, opt) {
								if (buttonId === 'yes') {
									window.location.href = PATH + '/logout';
								}
							},
							icon: Ext.window.MessageBox.QUESTION
						});
					}
				}, {
					xtype: 'combobox',
					name: 'theme',
					fieldLabel: '主题',
					labelWidth: 40,
					width: 110,
					store: Ext.create('Ext.data.Store', {
//					    fields: ['display', 'value'],
//					    data: Emp.getDictionarys('theme')
						model: 'Emp.model.Dictionary',
						autoLoad: true,
						proxy: {
							type: 'ajax',
							url: PATH + '/dictionary/query',
							extraParams: {
								code: 'theme'
							},
							reader: {
								type: 'json',
								root: 'datas',
								totalProperty: 'totalCount'
							}
						}
					}),
					queryMode: 'local',
					displayField: 'display',
					valueField: 'value',
					forceSelection: true,
					listeners: {
						'render': function(combo) {
							var theme = Ext.util.Cookies.get('theme');
							if(theme === null) {
								theme = 'ext-all.css';
							}
							this.setValue(theme);
						},
						'select': function (combo, records) {
							Ext.util.Cookies.clear('theme');
							Ext.util.CSS.swapStyleSheet('theme', Emp.ext + '/resources/css/'+ combo.getValue());
							Ext.util.Cookies.set('theme', combo.getValue());
						}
					}
				}]
			}]
        });
        this.callParent();
    }
})